package com.viknix.threadpool.manager.client.config;

import com.viknix.threadpool.manager.client.builder.ThreadPoolBuilder;
import com.viknix.threadpool.manager.client.enums.BlockingQueueEnum;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Dongqi
 * @Date: 2021/10/26 14:52
 * @Version 1.0
 * @Description: ThreadPoolBuilder 参数校验
 */
public class ThreadPoolBuilderGroupSequenceProvider implements DefaultGroupSequenceProvider<ThreadPoolBuilder> {

    @Override
    public List<Class<?>> getValidationGroups(ThreadPoolBuilder threadPoolBuilder) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(ThreadPoolBuilder.class);

        if (threadPoolBuilder != null) {
            if (threadPoolBuilder.isDynamicThreadPool()) {
                defaultGroupSequence.add(ThreadPoolBuilder.IsDynamicThreadPool.class);
            }
            if (threadPoolBuilder.getBlockingQueueCode() != null) {
                if (threadPoolBuilder.getBlockingQueueCode().equals(BlockingQueueEnum.ARRAY_BLOCKING_QUEUE)) {
                    defaultGroupSequence.add(ThreadPoolBuilder.IsArrayBlockingQueue.class);
                }
            }
        }
        return defaultGroupSequence;
    }
}
